namespace QMVnSoft.ReportForms
{
    using QMVnSoft;
    using QMVnSoft.Controls;
    using QMVnSoft.DAL;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormKTS05Viewer : FormReportViewer
    {
        private IContainer components;
        private LabelControl lblMa_Bp;
        private LabelControl lblMa_Nh_Ts;
        private LabelControl lblMa_Ts;
        private LabelControl lblNgay_Ct2;
        private TextSearch txtMa_Bp;
        private TextSearch txtMa_Nh_Ts;
        private TextSearch txtMa_Ts;
        private TextDate txtNgay_Ct2;
        private TextControl txtTen_Bp;
        private TextControl txtTen_Nh_Ts;
        private TextControl txtTen_Ts;

        public FormKTS05Viewer()
        {
            this.InitializeComponent();
            this.txtNgay_Ct2.Value = AppInstance.EndWorkingDate;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void FormKTS05Viewer_Load(object sender, EventArgs e)
        {
        }

        private void InitializeComponent()
        {
            //ComponentResourceManager manager = new ComponentResourceManager(typeof(FormKTS05Viewer));
            this.txtNgay_Ct2 = new TextDate();
            this.lblNgay_Ct2 = new LabelControl();
            this.lblMa_Ts = new LabelControl();
            this.lblMa_Nh_Ts = new LabelControl();
            this.txtTen_Nh_Ts = new TextControl();
            this.txtMa_Nh_Ts = new TextSearch();
            this.txtMa_Ts = new TextSearch();
            this.txtTen_Ts = new TextControl();
            this.lblMa_Bp = new LabelControl();
            this.txtMa_Bp = new TextSearch();
            this.txtTen_Bp = new TextControl();
            base.rptContainer.Panel1.SuspendLayout();
            base.rptContainer.SuspendLayout();
            base.SuspendLayout();
            base.rptContainer.Panel1.Controls.Add(this.txtTen_Bp);
            base.rptContainer.Panel1.Controls.Add(this.txtTen_Ts);
            base.rptContainer.Panel1.Controls.Add(this.txtTen_Nh_Ts);
            base.rptContainer.Panel1.Controls.Add(this.txtMa_Bp);
            base.rptContainer.Panel1.Controls.Add(this.txtMa_Ts);
            base.rptContainer.Panel1.Controls.Add(this.txtMa_Nh_Ts);
            base.rptContainer.Panel1.Controls.Add(this.lblMa_Bp);
            base.rptContainer.Panel1.Controls.Add(this.lblMa_Nh_Ts);
            base.rptContainer.Panel1.Controls.Add(this.lblMa_Ts);
            base.rptContainer.Panel1.Controls.Add(this.txtNgay_Ct2);
            base.rptContainer.Panel1.Controls.Add(this.lblNgay_Ct2);
            base.rptContainer.SplitterDistance = 0x58;
            this.txtNgay_Ct2.DateTimeFormat = TextDate.DateTimeFormatType.Date;
            this.txtNgay_Ct2.Font = new Font("Arial", 8.25f);
            this.txtNgay_Ct2.InsertKeyMode = InsertKeyMode.Overwrite;
            this.txtNgay_Ct2.Location = new Point(0x6c, 0x42);
            this.txtNgay_Ct2.Mask = "00/00/0000";
            this.txtNgay_Ct2.Name = "txtNgay_Ct2";
            this.txtNgay_Ct2.OldValue = null;
            this.txtNgay_Ct2.Size = new Size(100, 20);
            this.txtNgay_Ct2.TabIndex = 4;
//            this.txtNgay_Ct2.Value = null;//manager.GetObject("txtNgay_Ct2.Value");
            this.lblNgay_Ct2.AutoSize = true;
            this.lblNgay_Ct2.Font = new Font("Arial", 8.25f);
            this.lblNgay_Ct2.Location = new Point(12, 0x45);
            this.lblNgay_Ct2.Name = "lblNgay_Ct2";
            this.lblNgay_Ct2.Size = new Size(0x36, 14);
            this.lblNgay_Ct2.TabIndex = 0x61;
            this.lblNgay_Ct2.Text = "Đến ngày";
            this.lblMa_Ts.AutoSize = true;
            this.lblMa_Ts.Font = new Font("Arial", 8.25f);
            this.lblMa_Ts.Location = new Point(12, 0x1b);
            this.lblMa_Ts.Name = "lblMa_Ts";
            this.lblMa_Ts.Size = new Size(0x38, 14);
            this.lblMa_Ts.TabIndex = 0x73;
            this.lblMa_Ts.Text = "Mã tài sản";
            this.lblMa_Nh_Ts.AutoSize = true;
            this.lblMa_Nh_Ts.Font = new Font("Arial", 8.25f);
            this.lblMa_Nh_Ts.Location = new Point(12, 6);
            this.lblMa_Nh_Ts.Name = "lblMa_Nh_Ts";
            this.lblMa_Nh_Ts.Size = new Size(0x45, 14);
            this.lblMa_Nh_Ts.TabIndex = 0x73;
            this.lblMa_Nh_Ts.Text = "Nhóm tài sản";
            this.txtTen_Nh_Ts.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtTen_Nh_Ts.BackColor = SystemColors.Control;
            this.txtTen_Nh_Ts.BorderStyle = BorderStyle.None;
            this.txtTen_Nh_Ts.CheckTextSearched = false;
            this.txtTen_Nh_Ts.DisabledForeColor = Color.Blue;
            this.txtTen_Nh_Ts.Enabled = false;
            this.txtTen_Nh_Ts.Font = new Font("Arial", 8.25f);
            this.txtTen_Nh_Ts.ForeColor = Color.Blue;
            this.txtTen_Nh_Ts.Location = new Point(0xd6, 6);
            this.txtTen_Nh_Ts.Name = "txtTen_Nh_Ts";
            this.txtTen_Nh_Ts.OldValue = null;
            this.txtTen_Nh_Ts.Size = new Size(0x1ca, 13);
            this.txtTen_Nh_Ts.TabIndex = 0x75;
//            this.txtTen_Nh_Ts.Value = null;//manager.GetObject("txtTen_Nh_Ts.Value");
            this.txtMa_Nh_Ts.CharacterCasing = CharacterCasing.Upper;
            this.txtMa_Nh_Ts.CheckTextSearched = false;
            this.txtMa_Nh_Ts.DisabledForeColor = Color.Empty;
            this.txtMa_Nh_Ts.EmptyIsValid = true;
            this.txtMa_Nh_Ts.FieldDisplay = "Ten_Nh_Ts";
            this.txtMa_Nh_Ts.Font = new Font("Arial", 8.25f);
            this.txtMa_Nh_Ts.FoundIsValid = true;
            this.txtMa_Nh_Ts.Location = new Point(0x6c, 3);
            this.txtMa_Nh_Ts.MaxLength = 0x20;
            this.txtMa_Nh_Ts.Name = "txtMa_Nh_Ts";
            this.txtMa_Nh_Ts.OldValue = null;
            this.txtMa_Nh_Ts.Size = new Size(100, 20);
            this.txtMa_Nh_Ts.TabIndex = 0;
            this.txtMa_Nh_Ts.TableName = "DMNHTS";
            this.txtMa_Nh_Ts.TextDisplay = this.txtTen_Nh_Ts;
            this.txtMa_Nh_Ts.UserTextLength = AppInstance.TextControlLength.ItemCode;
            this.txtMa_Nh_Ts.UserTrimMode = AppInstance.TextControlTrimMode.All;
//            this.txtMa_Nh_Ts.Value = null;//manager.GetObject("txtMa_Nh_Ts.Value");
            this.txtMa_Ts.CharacterCasing = CharacterCasing.Upper;
            this.txtMa_Ts.CheckTextSearched = false;
            this.txtMa_Ts.DisabledForeColor = Color.Empty;
            this.txtMa_Ts.EmptyIsValid = true;
            this.txtMa_Ts.FieldDisplay = "Ten_Ts";
            this.txtMa_Ts.Font = new Font("Arial", 8.25f);
            this.txtMa_Ts.FoundIsValid = true;
            this.txtMa_Ts.Location = new Point(0x6c, 0x18);
            this.txtMa_Ts.MaxLength = 0x20;
            this.txtMa_Ts.Name = "txtMa_Ts";
            this.txtMa_Ts.OldValue = null;
            this.txtMa_Ts.Size = new Size(100, 20);
            this.txtMa_Ts.TabIndex = 1;
            this.txtMa_Ts.TableName = "DMTS";
            this.txtMa_Ts.TextDisplay = this.txtTen_Ts;
            this.txtMa_Ts.UserTextLength = AppInstance.TextControlLength.ItemCode;
            this.txtMa_Ts.UserTrimMode = AppInstance.TextControlTrimMode.All;
//            this.txtMa_Ts.Value = null;//manager.GetObject("txtMa_Ts.Value");
            this.txtTen_Ts.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtTen_Ts.BackColor = SystemColors.Control;
            this.txtTen_Ts.BorderStyle = BorderStyle.None;
            this.txtTen_Ts.CheckTextSearched = false;
            this.txtTen_Ts.DisabledForeColor = Color.Blue;
            this.txtTen_Ts.Enabled = false;
            this.txtTen_Ts.Font = new Font("Arial", 8.25f);
            this.txtTen_Ts.ForeColor = Color.Blue;
            this.txtTen_Ts.Location = new Point(0xd6, 0x1b);
            this.txtTen_Ts.Name = "txtTen_Ts";
            this.txtTen_Ts.OldValue = null;
            this.txtTen_Ts.Size = new Size(0x1ca, 13);
            this.txtTen_Ts.TabIndex = 0x75;
//            this.txtTen_Ts.Value = null;//manager.GetObject("txtTen_Ts.Value");
            this.lblMa_Bp.AutoSize = true;
            this.lblMa_Bp.Font = new Font("Arial", 8.25f);
            this.lblMa_Bp.Location = new Point(12, 0x30);
            this.lblMa_Bp.Name = "lblMa_Bp";
            this.lblMa_Bp.Size = new Size(90, 14);
            this.lblMa_Bp.TabIndex = 0x73;
            this.lblMa_Bp.Text = "Bộ phận sử dụng";
            this.txtMa_Bp.CharacterCasing = CharacterCasing.Upper;
            this.txtMa_Bp.CheckTextSearched = false;
            this.txtMa_Bp.DisabledForeColor = Color.Empty;
            this.txtMa_Bp.EmptyIsValid = true;
            this.txtMa_Bp.FieldDisplay = "Ten_Bp";
            this.txtMa_Bp.Font = new Font("Arial", 8.25f);
            this.txtMa_Bp.FoundIsValid = true;
            this.txtMa_Bp.Location = new Point(0x6c, 0x2d);
            this.txtMa_Bp.MaxLength = 0x20;
            this.txtMa_Bp.Name = "txtMa_Bp";
            this.txtMa_Bp.OldValue = null;
            this.txtMa_Bp.Size = new Size(100, 20);
            this.txtMa_Bp.TabIndex = 2;
            this.txtMa_Bp.TableName = "DMBP";
            this.txtMa_Bp.TextDisplay = this.txtTen_Bp;
            this.txtMa_Bp.UserTextLength = AppInstance.TextControlLength.ItemCode;
            this.txtMa_Bp.UserTrimMode = AppInstance.TextControlTrimMode.All;
//            this.txtMa_Bp.Value = null;//manager.GetObject("txtMa_Bp.Value");
            this.txtTen_Bp.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtTen_Bp.BackColor = SystemColors.Control;
            this.txtTen_Bp.BorderStyle = BorderStyle.None;
            this.txtTen_Bp.CheckTextSearched = false;
            this.txtTen_Bp.DisabledForeColor = Color.Blue;
            this.txtTen_Bp.Enabled = false;
            this.txtTen_Bp.Font = new Font("Arial", 8.25f);
            this.txtTen_Bp.ForeColor = Color.Blue;
            this.txtTen_Bp.Location = new Point(0xd6, 0x30);
            this.txtTen_Bp.Name = "txtTen_Bp";
            this.txtTen_Bp.OldValue = null;
            this.txtTen_Bp.Size = new Size(0x1ca, 13);
            this.txtTen_Bp.TabIndex = 0x75;
//            this.txtTen_Bp.Value = null;//manager.GetObject("txtTen_Bp.Value");
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.CheckDetailMost = true;
            base.ClientSize = new Size(0x31a, 0x1cf);
            base.Name = "FormKTS05Viewer";
            base.Load += new EventHandler(this.FormKTS05Viewer_Load);
            base.rptContainer.Panel1.ResumeLayout(false);
            base.rptContainer.Panel1.PerformLayout();
            base.rptContainer.ResumeLayout(false);
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        protected override void OnGenerateColumns()
        {
            object[][] objArray = new object[9][];
            object[] objArray2 = new object[4];
            objArray2[0] = "Ma_Ts";
            objArray2[1] = "Mã tài sản";
            objArray2[2] = "C";
            objArray[0] = objArray2;
            object[] objArray3 = new object[4];
            objArray3[0] = "Ten_Ts";
            objArray3[1] = "Tên tài sản";
            objArray3[2] = "C";
            objArray[1] = objArray3;
            object[] objArray4 = new object[4];
            objArray4[0] = "The_Ts";
            objArray4[1] = "Thẻ tài sản";
            objArray4[2] = "C";
            objArray[2] = objArray4;
            object[] objArray5 = new object[4];
            objArray5[0] = "Ngay_KH";
            objArray5[1] = "Ngày khấu hao";
            objArray5[2] = "C";
            objArray[3] = objArray5;
            object[] objArray6 = new object[4];
            objArray6[0] = "Nuoc_Sx";
            objArray6[1] = "Nước sản xuất";
            objArray6[2] = "C";
            objArray[4] = objArray6;
            objArray[5] = new object[] { "TienN2", "Nguyên giá", "N", AppInstance.TextNumericFormat.LocalAmount };
            objArray[6] = new object[] { "So_Thang", "Số tháng khấu hao", "N", AppInstance.TextNumericFormat.IntNumber };
            objArray[7] = new object[] { "TienH", "Khấu hao tháng", "N", AppInstance.TextNumericFormat.LocalAmount };
            objArray[8] = new object[] { "TienK2", "Khấu hao luỹ kế", "N", AppInstance.TextNumericFormat.LocalAmount };
            base.LocalColNames = objArray;
            base.OnGenerateColumns();
        }

        protected override void OnMakeReport()
        {
            AppInstance.EndWorkingDate = (DateTime) this.txtNgay_Ct2.Value;
            base.LocalTable = new ReportDataAccess().KTS01_Get(AppInstance.Subsidiaries, this.txtNgay_Ct2.Value, this.txtNgay_Ct2.Value, this.txtMa_Bp.Value, this.txtMa_Nh_Ts.Value, this.txtMa_Ts.Value, "C", AppInstance.DefLanguage);
            base.OnMakeReport();
        }

        protected override void OnPrint(bool pb_Printed)
        {
            if (((base.StimulReport != null) && (base.LocalTable != null)) && (base.LocalTable.Rows.Count != 0))
            {
                object obj2 = null;
                DataRow row = null;
                if ((base.DataGridBrowser.SelectedRows.Count != 0) && pb_Printed)
                {
                    foreach (DataGridViewRow row2 in base.DataGridBrowser.SelectedRows)
                    {
                        if (((DataRowView) row2.DataBoundItem).Row["Bold"].ToString() == "K")
                        {
                            row = ((DataRowView) row2.DataBoundItem).Row;
                            obj2 = row["Stt"];
                            this.PrintEachRow(pb_Printed, false, obj2, row);
                        }
                    }
                }
                else if (((DataRowView) base.DataGridBrowser.CurrentRow.DataBoundItem).Row["Bold"].ToString() == "K")
                {
                    row = ((DataRowView) base.DataGridBrowser.CurrentRow.DataBoundItem).Row;
                    obj2 = row["Stt"];
                    this.PrintEachRow(pb_Printed, false, obj2, row);
                }
            }
        }

        protected override void OnSendParameters()
        {
            base.StimulReport["Ngay"] = this.txtNgay_Ct2.Value;
        }

        private void PrintEachRow(bool pb_Printed, bool pb_OnlyOneRow, object ps_Stt, DataRow po_Row)
        {
            DataTable dataTable = new DmTsDataAccess().GetDetailTable3(ps_Stt);
            base.StimulReport.DataStore.Clear();
            base.StimulReport.RegData(base.ReportFile, dataTable);
            this.UpdateParameters();
            this.OnSendParameters();
            if (!po_Row["Ma_Ts"].Equals(DBNull.Value))
            {
                base.StimulReport["Ma_Ts"] = po_Row["Ma_Ts"];
            }
            if (!po_Row["Ten_Ts"].Equals(DBNull.Value))
            {
                base.StimulReport["Ten_Ts"] = po_Row["Ten_Ts"].ToString().Trim();
            }
            if (!po_Row["The_Ts"].Equals(DBNull.Value))
            {
                base.StimulReport["The_Ts"] = po_Row["The_Ts"];
            }
            if (!po_Row["So_Hieu"].Equals(DBNull.Value))
            {
                base.StimulReport["So_Hieu"] = po_Row["So_Hieu"];
            }
            if (!po_Row["So_Ct_T"].Equals(DBNull.Value))
            {
                base.StimulReport["So_Ct_T"] = po_Row["So_Ct_T"];
            }
            if (!po_Row["Ngay_Ts"].Equals(DBNull.Value))
            {
                base.StimulReport["Ngay_Ts"] = po_Row["Ngay_Ts"];
            }
            if (!po_Row["TienN2"].Equals(DBNull.Value))
            {
                base.StimulReport["TienN2"] = po_Row["TienN2"];
            }
            if (!po_Row["Nuoc_Sx"].Equals(DBNull.Value))
            {
                base.StimulReport["Nuoc_Sx"] = po_Row["Nuoc_Sx"];
            }
            if (!po_Row["Ten_Bp"].Equals(DBNull.Value))
            {
                base.StimulReport["Ten_Bp"] = po_Row["Ten_Bp"];
            }
            if (!po_Row["Ngay_KH"].Equals(DBNull.Value))
            {
                base.StimulReport["Ngay_KH"] = po_Row["Ngay_KH"];
            }
            if (!po_Row["Cong_Suat"].Equals(DBNull.Value))
            {
                base.StimulReport["Cong_Suat"] = po_Row["Cong_Suat"];
            }
            if (!po_Row["Nam_Sx"].Equals(DBNull.Value))
            {
                base.StimulReport["Nam_Sx"] = po_Row["Nam_Sx"];
            }
            if (!po_Row["Tien2"].Equals(DBNull.Value))
            {
                base.StimulReport["Tien2"] = po_Row["Tien2"];
            }
            if (!po_Row["TienK2"].Equals(DBNull.Value))
            {
                base.StimulReport["TienK2"] = po_Row["TienK2"];
            }
            if (!po_Row["Ngay_Giam"].Equals(DBNull.Value))
            {
                base.StimulReport["Ngay_Giam"] = po_Row["Ngay_Giam"];
            }
            if (!po_Row["Ten_Giam_Ts"].Equals(DBNull.Value))
            {
                base.StimulReport["Ten_Giam_Ts"] = po_Row["Ten_Giam_Ts"];
            }
            if (pb_Printed)
            {
                if (pb_OnlyOneRow)
                {
                    base.StimulReport.Print();
                }
                else
                {
                    base.StimulReport.Print(false);
                }
            }
            else
            {
                base.StimulReport.Show();
            }
        }
    }
}

